﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace DAL
{
    public class NhaSanXuatQuery : DataProvide
    {
        public List<NhaSanXuatDAL> LayDanhSachNhaSanXuat()
        {
            List<NhaSanXuatDAL> dsNhaSanXuat = new List<NhaSanXuatDAL>();
            SqlConnection chuoiKetNoi = null;
            try
            {
                base.Connect();
                chuoiKetNoi = connection;
                string sqlString = String.Format(@"SELECT * FROM NhaSanXuat");

                SqlDataReader dr = ExecuteReader(sqlString);
                while (dr.Read())
                {
                    NhaSanXuatDAL nsx = (NhaSanXuatDAL)GetDataRowFromDataReader(dr);
                    dsNhaSanXuat.Add(nsx);
                }
            }/*
            catch
            {
                return null;
            }*/
            finally
            {
                if (chuoiKetNoi != null && chuoiKetNoi.State == System.Data.ConnectionState.Open)
                    chuoiKetNoi.Close();
            }
            return dsNhaSanXuat;
        }

        protected override object GetDataRowFromDataReader(SqlDataReader dr)
        {
            NhaSanXuatDAL nsx = new NhaSanXuatDAL();
            nsx.MaNhaSanXuat = dr.GetString(0);
            if (!dr.IsDBNull(1))
                nsx.TenNhaSanXuat = dr.GetString(1);
            return (object)nsx;
        }
    }
}
